Now I want to do my server side stuff.
I'm going to make this window invisible so I don't have so I don't have it in my way.
Let's go to shop frame and then we'll say visible uncheck.
Let's go to server script service.
There it is.
Let's closed up.
And I want to get this prop test, property test, and I'm going to disable that so it doesn't run.
And then I'm going to open my property manager.
I'm going to put some of that property test in the property manager when we make our purchase, let's
scroll up to the top of our property manager and I need to add server storage because that's where we
have our houses and stuff.
So I'll do a local game, get service server storage, and then I also need another helper function.
I'll just put it at the top.
Let's do function prop, manage server and I'm going to call this get player lot.
So this is going to pass in.
We're going to pass in a player and it's going to tell you which lot that they're currently occupying
while you're playing the game.
Because remember, we we assign lots dynamically so it won't be the same one every time.
Let's do an if statement.
If property for the player exists and property for the player dot has lot, then the player owns a lot.
Let's loop through the lot collection, find out which one they own.
So we'll do for I and V in pairs.
And we got a lot collection here.
We'll do do.
And we'll say if player equals equals v dot owner dot value, that's there a lot, then we're going
to return V and V will be the lot that the player owns.
So how are we going to use this?
When are we going to use this?
Scroll down a little bit underneath.
I'm going to make another function, say local function prop manager.
I'm going to call this one, add property item and the player is going to get passed in and the actual
item is going to get passed in.
Maybe scroll up a little more.
So this one's this is the one that's going to mimic our property test script so much.
First thing we're going to do, Oh, we already have server storage.
I was going to get server storage, but we have it, so we'll do local item template.
Right?
We need the item template.
If you remember that for our property test, we'll do server storage, wait for child, and then we
got to get the item right.
That's either going to be the cabin or the fence.
We're going to pass it in dynamically.
This will work for both of them.
Then I want to clone that item.
So I'm going to say item clone equals item temp, colon clone.
We're going to make another copy and then we're going to get the lot to put the item on.
So that's when we're going to use our prop manager module script function, right?
So you have to prepend it with the table name.
Even if you're inside the module script we'll do get was a get player lot pass in the player what else.
Oh let's get the item clone and the parent is going to be the lot then remember we got that anchor thing
right?
So we'll say local anchor.
This is the line up, the item we'll say Lot dot anchor Whoops, that's a capital lot.
Dot anchor.
Good.
Now we're going to need our pivot.
Right.
We're going to get the the C frame of the anchor using that p PV instance base class.
That's where it's at.
You don't need to know that.
We're just going to do anchor get pivot.
That's going to give us a C frame on the anchor to line up our item with, and then we'll do the item
clone, pivot to pivot to pass in the pivot.
All right.
Now you're probably thinking, where does this get called?
Well, it's going to get called in a couple of places, but one of the places the first place that's
going to get called is on the server side of our shop.
So let's go to the shop, update that now.
We're going to go to the bell.
And that's where the the top of the bell I have the Activate shop script.
Let's open that up.
The reason I did that property manager stuff first is because we're going to need it.
I'm going to get a variable for the property manager prop MGR.
We are going to require that script game dot server Script service.property manager.
Now remember, when we open it up, we're going to send data to our client so we can check to see if
they have a lot.
See if they already have the property.
So I'm going to pass in that second value prop manager get player items to save.
Let's let's use that one because that returns all the player items and we're just going to pass in a
player.
So on the on the client side, remember we had data we didn't have player just keep in mind fire client
this says where where we're going to go to and this is the first parameter that gets passed over on
the client side.
So that's the data.
If you remember that if you don't, it's understandable.
We did a lot, but you can go poking around in there.
So this here fires when the client, the player hits the buy button, right?
And then it sends a remote event back to the server, back to this activate shop script.
And we have a player, we have an item, we have a price.
But we also started passing in the property type, right?
We got prop type and when we did our tools, we went to replicated storage, checked first.
It's not in replicated storage, right?
We put it in server storage.
So this if statement is not going to work because we're not actually checking.
And we can't put it in our backpack, whatever it was, because it's not a tool, it's a piece of property.
So let's get rid of that.
If statement, let's get rid of this end because that was the end for the if and I'll format my document.
There we go.
We're going to add a few lines here, though.
We're going to use the property manager to add property item to the world.
Right.
We're not putting it on the character anymore.
The character will own it, but we're putting it in the world on his lot.
So we'll just say player and then that's the item that's going to be like the cabin or the fence.
And then we got to add it to their inventory.
So add item to player's inventory so that it saves off.
We'll get the player, we'll get the prop type, what do we call that?
IntelliSense kills me.
Prop type right here.
Right.
It's a key value pair.
That's how we're saving it.
So that's going to be like house or fence.
And then this is going to be the item that's going to be cabin or fence.
We should have made it like wood fence, right?
All right.
That's looking good.
Now, if we test it, we should see the property plop onto the lot when we buy it.
The downside is we still haven't done the equip player with the property.
So when they go back in the game, you're not going to have the house available yet, but it's going
to be easy.
Fix So let's get the cabin.
Buy a house.
Oh, look at that.
And then I think we have enough for the fence, too, right?
That's.
You bought the fence.
Let's check for errors in the output window.
That's looking good.
Here's our data, too.
That's being saved off.
So I open that up here.
Let's make this bigger so we can see it.
We want to make sure that the data is going to the data store being saved off.
Yeah, we got the house.
We got a cabin down here.
We got the cabin and the fence.
That's looking pretty good.
Now let's go ahead and equip the player when they enter the game, because now if you enter the game,
you're not going to get that house.
You're going to have it in your data.
It's just not going to be visible.
Let's take a look real quick.
Right.
It's not there yet.
We have to add it to equip player.
Let's do that now.
I am in my property manager.
This is under server script service.
We're going to scroll down to equip player and we're already giving them the lot and setting the beam.
But we need to check for the house and the fence now.
So I'm going to say if property for the player, we already know that it exists because we checked that
here, we checked it for the lot, but now let's check it for the house.
So if house then prop manager add property item, right?
Just like when we bought it, we're going to pass in the player.
We're going to pass in the property for the player and we're going to use the house key, which is house.
And then it should say cabin because we have it.
We only have a cabin and we're going to do the exact same thing for the fence, right?
Control C Let's scroll this up a little bit.
Control V, we're going to change this to fence and we're going to change this to fence, and now we're
going to play it.
And we should see our house when we enter the game because it did save off to the data store when we
were checking it last when we bought them.
We're going to have to check this.
Oh, look at that.
We're going to have to check this with the test server, too.
And our beam shuts off.
Cool.
And there we go in our house.
I was pretty good.
I like it.